package com.xiaoluyy.rpc.register;


import com.xiaoluyy.rpc.proxy.RpcClientProxy;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


public class RpcClientFactoryBean implements FactoryBean<Object>, ApplicationContextAware {
    private Class<?> type;
    private ApplicationContext applicationContext;



    private String systemCode;

    public RpcClientFactoryBean() {
    }

    public Class<?> getType() {
        return this.type;
    }

    public void setType(Class<?> type) {
        this.type = type;
    }

    public Class<?> getObjectType() {
        return this.type;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public String getSystemCode() {
        return systemCode;
    }

    public void setSystemCode(String systemCode) {
        this.systemCode = systemCode;
    }

    public boolean isSingleton() {
        return true;
    }

    public Object getObject() {
        // 找到对应的 thriftClient
        RpcClientProxy<?> subjectProxy2 = new RpcClientProxy<>(this.type, applicationContext);
        return subjectProxy2.newProxyInstance();

    }

}